home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Kernel / Em / badsignal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-17  |  4.0 KB  |  114 lines

  1.  
  2. /*  C O P Y R I G H T   N O T I C E :                                     */
  3. /* Copyright 1986 Eric Jul and Norm Hutchinson.     May not be used for any  */
  4. /* purpose without written permission from the authors.              */
  5.  
  6. /* Emerald handler to catch bad ULTRIX signals.                           */
  7. /* If the signal is in user code then fail the current process else       */
  8. /* crash the kernel.                                                      */
  9.  
  10. /* EXPORTS:             EmBadSignal                                       */
  11.  
  12. /* Author:              Eric Jul, November 1986                           */
  13.  
  14. #include <signal.h>
  15. #include <stdio.h>
  16. #include "Kernel/h/kEvents.h"
  17. #include "Kernel/h/kmdTypes.h"
  18. #include "Kernel/h/emTypes.h"
  19. #include "Kernel/h/utils.h"
  20. #include "Kernel/h/system.h"
  21.  
  22. extern int             perror();
  23. extern int           etext;
  24. extern char *           sbrk();
  25.  
  26. extern int              BadSigJumpPoint; /* in kernel stub */
  27. extern unsigned int     BadSigPC;        /* in kernel stub */
  28. extern SSPtr            currentSSP, preemptRunning();
  29. extern void             dofail();
  30. extern void             shutdownOID();
  31.  
  32. /**********************************************************************/
  33. /*      EmBadSignal                                                   */
  34. /**********************************************************************/
  35. /* ought to be void*/
  36. EmBadSignal(fSig, fCode, fContext)
  37. int                 fSig;
  38. int                 fCode;
  39. struct sigcontext  *fContext;
  40. /* For param description, see sigvec(2), ULTRIX manual                */
  41. {
  42.     unsigned int            limit = (unsigned int) sbrk(0);
  43.     struct sigvec           vec;    /* used in sigvec() calls     */
  44.  
  45.     KMDTrace("Failure", 3, "BadSignal(%d), Code = %d,  IP = 0x%04x\n", fSig,
  46.     fCode, fContext->sc_pc);
  47.  
  48.     BadSigPC        = (unsigned int) fContext->sc_pc;
  49.     if (
  50.     NonNULL(currentSSP)
  51.     &&  (((unsigned int) fContext->sc_pc) > (unsigned int) (&etext))
  52.     &&  (((unsigned int) fContext->sc_pc) < limit)) {
  53.     /* it was in the user area, fail it */
  54.     /* We force the failure by setting the pc to an address in the
  55.        kernel stub which forces a kernel call */
  56.     KMDTrace("Failure", 3, "Failing process\n");   
  57.     fContext->sc_pc = (int) &BadSigJumpPoint;
  58.     return;
  59.     } else {
  60.       /* It was an error in either the Emerald compiler or the
  61.        * Emerald kernel, so die.
  62.        * To die, remove the signal handler and redo the offending
  63.        * instruction as to cause UNIX to core dump with the
  64.        * system in the appropriate place and with the appropriate
  65.        * stack.
  66.        */
  67.       ErrMsg( "Cannot handle BadSignal(%d), Code = %d, IP = 0x%04x\n", fSig,
  68.          fCode, fContext->sc_pc);
  69.  
  70.       /* Emergency shutdown on bad signal -- kernel broken */
  71.       HoldSigs(); /* Watch out for this */
  72. #ifdef BSD
  73.       (void) fflush(stdout);
  74.       (void) fflush(stderr);
  75. #endif
  76.       printf("**** Signal no. %d arrived -- starting crash termination.\n", fSig);
  77.  
  78.       SendShutDownMsg(GetLNN());
  79.  
  80.       shutdownOID();
  81.  
  82.       vec.sv_handler      = SIG_DFL;
  83.       vec.sv_mask         = 0;      /* All signals enabled */
  84.       vec.sv_onstack      = 0;      /* Use main stack */
  85. #ifdef xkernel
  86. #else
  87.       if (sigvec(fSig, &vec, 0) < 0) {
  88.     perror("BadSignal:sigvec");
  89.       }
  90.       (void) sigsetmask(0);
  91. #endif
  92.       /* Now return and UNIX will do a core dump */
  93.       return;
  94.     }
  95. }
  96. /************************************************************************/
  97. /* Kernel call */
  98. void BadSignalOccurred()
  99. /* called from the kernel stub when a process has received a bad signal */
  100. /* the call looks like it was performed by the offending instruction, i.e.,
  101.    the IP points to the next instruction */
  102. {
  103.     KMDTrace("Failure", 3, "Recovering from a bad signal\n");
  104.     if (IsNIL(currentSSP->regs.g) || (IsNIL(currentSSP->regs.b))) {
  105.     /* This was the problem */
  106.     KMDTrace("Failure", 3, "NIL invoked: propagating failure\n");
  107.     dofail(preemptRunning(), TRUE);
  108.     return;
  109.     } 
  110.     
  111.     KMDTrace("Failure", 3, "Bad reference in %s\n", PPSSPlace(currentSSP));
  112.     dofail(preemptRunning(), FALSE);
  113. }
  114.